﻿<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>选择测试仪器</title>  
     <base target="_self"/>
    <%@include file="../jslib/jquerylib.jsp" %>
    <link rel="stylesheet" type="text/css" href="<%=path %>/web/style/layout.css" />
    <script type="text/javascript" src="<%=path %>/jslib/jquery.validate.min.js"></script>
    <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/jquery.form.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/additional-methods.js"></script>
  </head>
  <script>
         var api = frameElement.api;
         if (api!=undefined)
         {
         	var W = api.opener;
         }
         var junyansid = "<%=request.getParameter("junyansid")%>";
  		    $(document).ready(function(){
			    $('input[type="text"]').addClass('input_text');
				
				$("#fromTable").jqGrid({
					url:common_basePath+'junyansYiqiAction!querySelectYiqi.action?junyansid='+junyansid+'&type=all&temp='+Math.round(Math.random()*10000),
					datatype: "json",
					width : 420,
		            height : 320,
					colNames:['主键','仪器类型','仪器名称','规格型号','制造厂商'],
					colModel:[{name:'ID',index:'ID',key:true,hidden:true, width:100,hidedlg:true},
					          {name:'YIQILX',index:'YIQILX', width:100},
					          {name:'YIQIMC',index:'YIQIMC', width:100},
					          {name:'GUIGEXH',index:'GUIGEXH', width:60},
					          {name:'ZHIZAOCS',index:'ZHIZAOCS', width:60}],
					shrinkToFit:false,
					sortname:'ID',
					sortorder:'desc',
					viewrecords:true,
					multiselect: true, // 是否显示复选框
					multiboxonly : true, 
					rownumbers: false,//显示行号
					editable:true, 
					rowNum:<%=session.getAttribute("SYS_PAGECOUNT")%>,
					rowList:[15,20,50,200,500],
					toolbar: [false,"top"],
					jsonReader: {
						root:"rows",		// 数据行（默认为：rows）
						page: "page",  	// 当前页
						total: "total",  // 总页数
						records: "records",  // 总记录数
						repeatitems : false		// 设置成false，在后台设置值的时候，可以乱序。且并非每个值都得设
					},
					prmNames:{rows:"rows",page:"page",sort:"sidx",order:"sord",search:"search"},
					pager:"#fromPager",
					caption: "测试仪器列表",
					ondblClickRow : function(rowid) {
						addYiqiTo(rowid);
					}
				});
				
				//已选项目列表
				$("#toTable").jqGrid({
					url:common_basePath+'junyansYiqiAction!querySelectYiqi.action?junyansid='+junyansid+'&type=select&temp='+Math.round(Math.random()*10000),
					datatype: "json",
					width : 420,
		            height : 320,
					colNames:['主键','仪器类型','仪器名称','规格型号','制造厂商'],
					colModel:[{name:'ID',index:'ID',key:true,hidden:true, width:100,hidedlg:true},
					          {name:'YIQILX',index:'YIQILX', width:100},
					          {name:'YIQIMC',index:'YIQIMC', width:100},
					          {name:'GUIGEXH',index:'GUIGEXH', width:60},
					          {name:'ZHIZAOCS',index:'ZHIZAOCS', width:60}],
					shrinkToFit:false,
					sortname:'ID',
					sortorder:'desc',
					viewrecords:true,
					multiselect: true, // 是否显示复选框
					multiboxonly : true, 
					rownumbers: false,//显示行号
					editable:true, 
					rowNum:<%=session.getAttribute("SYS_PAGECOUNT")%>,
					rowList:[15,20,50,200,500],
					toolbar: [false,"top"],
					jsonReader: {
						root:"rows",		// 数据行（默认为：rows）
						page: "page",  	// 当前页
						total: "total",  // 总页数
						records: "records",  // 总记录数
						repeatitems : false		// 设置成false，在后台设置值的时候，可以乱序。且并非每个值都得设
					},
					prmNames:{rows:"rows",page:"page",sort:"sidx",order:"sord",search:"search"},
					pager:"#toPager",
					caption: "已选仪器列表",
					ondblClickRow : function(rowid) {
						delYiqiTo(rowid);
					}
				});
				
				//选择按钮
				$("#to").click(function() {
						var s = $("#fromTable").jqGrid('getGridParam', 'selarrrow') + "";
						if (s){
							addYiqiTo(s);
						}
					});
					
					function addYiqiTo(ids){
						$.ajax({
							type: "POST",
							async: false,//取消异步提交
							url: common_basePath+'junyansYiqiAction!addYiqiTo.action?yiqiids='+ids+'&junyansid='+junyansid,
							dataType: "json",
						    success : function(data, textStatus) {  
									if(data.result=='success'){
										gridSearchTo();
							        	gridSearchFrom();													
									}else{
										alert("操作错误！")
									}
								}
							});
					}
					
					
					//删除已选的检测仪器
					$("#from").click(function() {
					    var biaozhunIds = [];
						var ids= $("#toTable").jqGrid('getGridParam', 'selarrrow') + "";
						if (ids){
							delYiqiTo(ids);
						}
					});
					
					function delYiqiTo(ids){
						$.ajax({
							type: "POST",
							async: false,//取消异步提交
							url: common_basePath+'junyansYiqiAction!delYiqiTo.action?yiqiids='+ids+'&junyansid='+junyansid,
							dataType: "json",
							success : function(data, textStatus) {  
								if(data.result=='success'){
									gridSearchTo();
						        	gridSearchFrom();													
								}else{
									alert("操作错误！")
								}
							}
						});
					}
				
					/**
					 * 取消
					 */
					$("#clos").click(function() {
						api.close();
					});
			});
			
		function gridSearchFrom(){
		    var yiqimc = $.trim($("#yiqimc").val());
			var params = {  
			          "yiqimc" : encodeURIComponent($.trim(yiqimc))
			};							 
			 var postData = $("#fromTable").jqGrid("getGridParam", "postData");
			 $.extend(postData, params);
			jQuery("#fromTable").jqGrid('setGridParam',
			{
				url:common_basePath+'junyansYiqiAction!querySelectYiqi.action?junyansid='+junyansid+'&type=all&temp='+Math.round(Math.random()*10000)
			}).trigger("reloadGrid", [{page:1}]); 
		}
		function reset(){
		    $("#yiqimc").val('');
		}

		//右侧列表刷新
		function gridSearchTo(){
			 jQuery("#toTable").jqGrid('setGridParam',
			 {
				url:common_basePath +'junyansYiqiAction!querySelectYiqi.action?junyansid='+junyansid+'&type=selected&&temp='+Math.round(Math.random()*10000)
			 }).trigger("reloadGrid", [{page:1}]); 
		} 
		 
  </script>
  <body style='padding-left:20px;'>
  	<div id="search"  >
		<table border="0" cellpadding="4" cellspacing="1"  >
			<tr>
				<td class="td_label_user">检测仪器：</td>
				<td class="td_value"><input type="text" id="yiqimc" name="yiqimc"  style="width:200px;" value=""/></td>
				<td align="left">
					<input type="button" class="button_b" value="查&nbsp;询" onclick="gridSearchFrom()"/>
					<input type="button" class="button_b" value="清&nbsp;空" onclick="reset()"/>
					<button id="clos" class="button_b">确&nbsp;定</button>
				</td>
			</tr>
			</table>		
	</div>
    <div style="float: left">
        <table id='fromTable'></table><div id='fromPager'></div>
    </div>
    <div style="width:60px;height:200px;float:left;align: center;padding-top: 100px;">
        <button id="to" class="button_b" >选&nbsp;择</button><br /><br />     
        <button id="from" class="button_b" >删&nbsp;除</button><br />
    </div>
    <div style="float: left">
        <table id='toTable'></table><div id='toPager'></div>
    </div>

  </body>
</html>
